package com.rd.student.dashuju.zhengchengxiang.day0808;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Scanner;

public class StudentTest {
    public static void main(String[] args) throws Exception {
        BufferedWriter bw = new BufferedWriter(new FileWriter("Student.txt"));
        String str = "姓名 语文成绩 数学成绩 总分\n";
        bw.write(str);
        // 学生个数
        int number = 3;
        for (int i = 0; i < number; i++) {
            str = "";
            // 键盘录入
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入姓名：");
            String name = sc.nextLine();
            System.out.println("请输入语文成绩：");
            int chinese = sc.nextInt();
            System.out.println("请输入数学成绩：");
            int math = sc.nextInt();
            if ((chinese >= 0 && chinese <= 100) && (math >= 0 && math <= 100)) {
                Student student = new Student(name, chinese, math);
                int score = student.score();
                str = name + " " + chinese + " " + math + " " + score + "\n";
                bw.write(str);
            } else {
                System.out.println("分数有误！请重新输入");
                i--;
            }
        }
        bw.close();
    }
}

class Student {
    String name;
    int chinese;
    int math;

    public Student(String name, int chinese, int math) {
        this.name = name;
        this.chinese = chinese;
        this.math = math;
    }

    public int score() {
        return chinese + math;
    }
}
